MongoDB limit() Method
Use limit() method to show the limited number of documents in a collection with find() method.
Syntax:
db.COLLECTION_NAME.find().limit(NUMBER)
Example:
For example users collection have 19 documents. Now you need to get only first 2 documents from collection.
> db.users.find().limit(2);
Output:
{ "_id" : ObjectId("59a01b102427abe3470644db"), "id" : 1001, "user_name" : "rahul", "name" : [ { "first_name" : "Rahul" }, { "middle_name" : "" }, { "last_name" : "Kumar" } ], "email" : "[email protected]", "designation" : "Founder and CEO", "location" : "India" } { "_id" : ObjectId("59a01b2f2427abe3470644dc"), "id" : 1002, "user_name" : "jack", "name" : [ { "first_name" : "Jack" }, { "middle_name" : "" }, { "last_name" : "Daniel" } ], "email" : "[email protected]", "designation" : "Director", "location" : "California" }